package com.vvvtimes.main;

import java.util.UUID;

import com.vvvtimes.utils.*;


public class Main {

    // 主函数
    public static void main(String[] args) throws Exception {
        // 注意 Windows需要开启支持文件名大小写
        // fsutil.exe file queryCaseSensitiveInfo <path>
        // fsutil.exe file setCaseSensitiveInfo <path> enable
        // fsutil.exe file setCaseSensitiveInfo <path> disable
        // 若提示不支持该请求，则用powershell命令行管理员模式执行
        // Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

        //fsutil.exe file setCaseSensitiveInfo D:\caseSensitiveFolder enable
        String oldJarPath = "D:\\caseSensitiveFolder\\instrumented-restful-fast-request-pro-2024.1.1.jar"; //原jar路径
        //String oldJarPath = "/root/instrumented-restful-fast-request-pro-2023.2.2.1.jar"; //原jar路径
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        String name = oldJarPath.substring(0, oldJarPath.lastIndexOf("."));
        String outClassPath = name + uuid; //解压临时文件路径
        String newJarPath = name + "_Crack.jar"; //重新压缩后的jar路径

        System.out.println("原jar路径：" + oldJarPath);
        System.out.println("解压临时文件路径：" + outClassPath);
        System.out.println("新jar路径：" + newJarPath);

        //解压
        Decompression.uncompress(oldJarPath, outClassPath);

        //删除xml 字符串
        DeleteLineUtil.removeLineFromFile(outClassPath + "/META-INF/plugin.xml", "PFASTREQUEST");

        //获取版本号
        String version = VersionUtil.getVersionFromXml(outClassPath + "/META-INF/plugin.xml");

        //输出class
        CrackClass.crack(oldJarPath, outClassPath, version);

        //压缩
        Compressor.compress(newJarPath, outClassPath);

        //删除压缩的文件夹
        if (StrongFileUtil.deleteDirPath(outClassPath)) {
            System.out.println("删除压缩临时文件夹成功");
        }
    }
}